﻿//-----------------------------------------------------------------------
// <copyright file="PointViewModel.cs" company="Microsoft">
//     Copyright (c) AGALTIER, Microsoft. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace ArchiSimple.Windows.ViewModel.PlanObjects
{
    using System;
    using System.Linq;
    using ArchiSimple.Windows.Model;
    using ArchiSimple.Windows.Tools;
    using System.Collections.Generic;
#if NETFX_CORE
    using global::Windows.UI.Xaml;
    using global::Windows.UI.Xaml.Media;
#else
    using System.Windows.Media;
#endif

    /// <summary>
    /// TODO: Provide summary section in the documentation header.
    /// </summary>
    public class PointViewModel : PlanObjectViewModel<Point>
    {
        public PointViewModel(PlanViewModel plan, Point model, Designer designer)
            : base(plan, model, designer)
        {
            this.NextPoints = new List<PointViewModel>();
            RefreshGeometry();
        }

        private void RefreshGeometry()
        {
            this.Zone = new Rectangle
            {
                X = this.X - 5,
                Y = this.Y - 5,
                Width = 10,
                Height = 10,
            };
        }

        public override PathGeometry SelectedGeometry
        {
            get
            {
                return null;
            }
        }

        public double X
        {
            get { return this.Current.X; }
            set
            {
                this.Current.X = value;
                RaisePropertyChanged(() => X);
                RefreshGeometry();
            }
        }

        public double Y
        {
            get { return this.Current.Y; }
            set
            {
                this.Current.Y = value;
                RaisePropertyChanged(() => Y);
                RefreshGeometry();
            }
        }

        public List<PointViewModel> NextPoints { get; set; }

        public override void Delete()
        {
            if (this.NextPoints.Count == 0)
            {
                this.Plan.RemoveFromPlan(this);
            }
        }
    }
}
